#include "Common.h"

Unit::Unit()
{
}

void Unit::SetSpeed(ui32 type, float value)
{
	RealmPacket data(0, 0);
	if(type != 4)
	{
		data << m_guid << m_speedchanged++;
		if(type == 1)
			data << ui8(1);
		data << value;
	}
	else
	{
		data << m_guid << ui32(0) << ui8(0) << ui32(GetTickCount());
		data << m_position._x << m_position._y << m_position._z << float(1.0f);
		data << ui32(0) << value;
	}
	switch(type)
	{
	case 1:
		{
			data.SetOpcode(SMSG_FORCE_RUN_SPEED_CHANGE);
			m_runspeed = value;
			break;
		}
	case 2:
		{
			data.SetOpcode(SMSG_FORCE_RUN_BACK_SPEED_CHANGE);
			m_backrunspeed = value;
			break;
		}
	case 3:
		{
			data.SetOpcode(SMSG_FORCE_SWIM_SPEED_CHANGE);
			m_swimspeed = value;
			break;
		}
	case 4:
		{
			data.SetOpcode(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE);
			m_backswimspeed = value;
			break;
		}
	case 5:
		{
			data.SetOpcode(SMSG_FORCE_FLIGHT_SPEED_CHANGE);
			m_flyspeed = value;
			break;
		}
	}
	SendToSet(data);
}